{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Exception in Tkinter callback\n",
      "Traceback (most recent call last):\n",
      "  File \"c:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\tkinter\\__init__.py\", line 1967, in __call__\n",
      "    return self.func(*args)\n",
      "           ^^^^^^^^^^^^^^^^\n",
      "  File \"C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_17132\\2136541867.py\", line 50, in ButtonCaptureClick\n",
      "    w=MyCapture(filename)\n",
      "      ^^^^^^^^^^^^^^^^^^^\n",
      "  File \"C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_17132\\2136541867.py\", line 25, in __init__\n",
      "    self.image=thinter.PhotoImage(file=png)\n",
      "               ^^^^^^^\n",
      "NameError: name 'thinter' is not defined\n"
     ]
    }
   ],
   "source": [
    "import tkinter\n",
    "import tkinter.filedialog\n",
    "import tkinter.messagebox\n",
    "import os\n",
    "from PIL import ImageGrab,Image\n",
    "from time import sleep\n",
    "\n",
    "root=tkinter.Tk()\n",
    "root.geometry('100x40+400+300')\n",
    "root.resizable(False,False)\n",
    "\n",
    "class MyCapture:\n",
    "    def __init__(self,png):\n",
    "        self.X=tkinter.IntVar(value=0)\n",
    "        self.Y=tkinter.IntVar(value=0)\n",
    "        \n",
    "        screen_width=root.winfo_screenwidth()\n",
    "        screen_height=root.winfo_screenheight()\n",
    "\n",
    "        self.top=tkinter.Toplevel(root,\n",
    "        width=screen_width,height=screen_height)\n",
    "        self.top.overrideredirect(True)\n",
    "        self.canvas=tkinter.Canvas(self.top,bg='white',\n",
    "        width=screen_width,height=screen_height)\n",
    "        self.image=thinter.PhotoImage(file=png)\n",
    "        self.canvas.creat_image(screenWidth//2,screenHeight//2,image=self.image)\n",
    "\n",
    "        def onLeftButtonUp(event):\n",
    "            im=image.open(png)\n",
    "            color=im.getpixel((event.x,event.y)) [:3]\n",
    "            msg=str(color)+'\\n'\n",
    "            color='#'+''.join(map(lambda x:hex(x)[2:],color))\n",
    "            msg+=color\n",
    "            tkinter.messagebox.showinfo('',msg)\n",
    "\n",
    "            self.top.destroy()\n",
    "            self.canvas.bind('<Button-1>',onLeftButtonUp)\n",
    "          \n",
    "            self.canvas.pack(fill=tkinter.BOTH,expand=tkinter.YES)\n",
    "\n",
    "def ButtonCaptureClick():\n",
    "    root.state('icon')\n",
    "    sleep(0.2)\n",
    "    \n",
    "    filename='temp.png'\n",
    "    im=ImageGrab.grab()\n",
    "    im.save(filename)\n",
    "    im.close()\n",
    "\n",
    "    w=MyCapture(filename)\n",
    "    ButtonCapture.wait_window(w.top)\n",
    "\n",
    "    root.state('normal')\n",
    "    os.remove(filename)\n",
    "buttonCapture=tkinter.Button(root,text='Capture',command=ButtonCaptureClick)\n",
    "buttonCapture.place(x=10,y=10,width=80,height=30)\n",
    "\n",
    "root.mainloop()\n",
    "\n",
    "                     "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.9"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
